<?php

namespace app\common\model;

use think\Model;


class BenfitLog extends Model
{

    

    

    // 表名
    protected $name = 'benfit_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'type_text'
    ];
    

    
    public function getTypeList()
    {
        return ['none' => __('Type none'), 'buy' => __('Type buy'), 'use' => __('Type use'), 'back' => __('Type back')];
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function user()
    {
        return $this->belongsTo('\app\admin\model\xykeep\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(1);
    }

    public function card()
    {
        return $this->belongsTo('\app\common\model\Card', 'card_id','id',[])->setEagerlyType(1);
    }

    public function benfit()
    {
        return $this->belongsTo('\app\common\model\Benfit', 'benfit_id','id',[])->setEagerlyType(1);
    }

}
